package part18;

import java.io.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author wcj
 * @Date 2021/6/4 18:27
 * @Version 1.0
 */
public class Part1834 implements Serializable {

    private Date date = new Date();
    private String username;
    private transient String password;

    public Part1834(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public String toString() {
        return "Login info:[username:" + username + ",password:" + password + ",Date:" + date + "]";
    }

    /**
     * transient关键字禁止字段的序列化，可以用于一些对象中的敏感信息字段，例如password
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Part1834 wcj = new Part1834("wcj", "123456");
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("./src/part18/login.out"));
        out.writeObject(wcj);
        out.close();

        TimeUnit.MILLISECONDS.sleep(1);

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("./src/part18/login.out"));
        Part1834 part1834 = (Part1834) in.readObject();
        System.out.println(part1834);
    }
}
